package hz.mobileproject.pda.toolsmanager.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;

import java.util.ArrayList;
import java.util.List;

import hz.mobileproject.pda.R;
import hz.mobileproject.pda.toolsmanager.bean.JuLuLeftClickBean;
import hz.mobileproject.pda.toolsmanager.fragment.FaFangCallFragment;
import hz.mobileproject.pda.toolsmanager.fragment.GuiHuanJiLuFragment;
import hz.mobileproject.pda.toolsmanager.fragment.KuCunFragment;
import hz.mobileproject.pda.toolsmanager.fragment.ScrapFragment;
import hz.mobileproject.pda.toolsmanager.fragment.ShouHuiFragment;
import hz.mobileproject.pda.toolsmanager.fragment.StationBGFragment;
import hz.mobileproject.pda.toolsmanager.fragment.WaiJieJiLuFragment;
import hz.mobileproject.pda.toolsmanager.fragment.XiaoJianManageFragment;
import hz.mobileproject.pda.ui.base.BaseScanActivity;

@ContentView(R.layout.activity_tool_call_jilu)
public class ToolCallJiLuActivity extends BaseScanActivity implements RadioGroup.OnCheckedChangeListener {


    @ViewInject(R.id.vp)
    private ViewPager vp;
    @ViewInject(R.id.rg_jilu)
    private RadioGroup rg_jilu;
    @ViewInject(R.id.rb_1)
    private RadioButton rb_1;
    @ViewInject(R.id.rb_2)
    private RadioButton rb_2;
    @ViewInject(R.id.rb_3)
    private RadioButton rb_3;
    @ViewInject(R.id.rb_4)
    private RadioButton rb_4;
    @ViewInject(R.id.rb_5)
    private RadioButton rb_5;
    @ViewInject(R.id.rb_6)
    private RadioButton rb_6;
    @ViewInject(R.id.rb_7)
    private RadioButton rb_7;
    @ViewInject(R.id.rb_8)
    private RadioButton rb_8;


    private List<JuLuLeftClickBean> clickBeans = new ArrayList<>();

    private List<Fragment> mFragments = new ArrayList<>();
    private FragmentPagerAdapter mAdapter;


    @Override
    protected void onSaveInstanceState(Bundle outState) {
//        super.onSaveInstanceState(outState);
    }

    @Override
    protected void initData() {
        setTitleText("工具记录");
        //初始化右侧Fragment

        mFragments.add(new FaFangCallFragment());   //发放
        mFragments.add(new ShouHuiFragment());  //收回
        mFragments.add(new ScrapFragment());   //报废

        mFragments.add(new KuCunFragment());
        mFragments.add(new WaiJieJiLuFragment());
        mFragments.add(new GuiHuanJiLuFragment());
        mFragments.add(new StationBGFragment());
        mFragments.add(new XiaoJianManageFragment());

        mAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return mFragments.get(position);
            }

            @Override
            public int getCount() {
                return mFragments.size();
            }
        };
        vp.setOffscreenPageLimit(0);
        vp.setCurrentItem(0);
        vp.setAdapter(mAdapter);
        rg_jilu.setOnCheckedChangeListener(this);
        vp.addOnPageChangeListener(mOnPageChangeListener);
    }

    @Override
    protected void onScanSucesess(int requestCode, String scanMsg) {

    }


    @Override
    public void onCheckedChanged(RadioGroup radioGroup, int i) {
        switch (i) {
            case R.id.rb_1:
                vp.setCurrentItem(0,false);
                break;
            case R.id.rb_2:
                vp.setCurrentItem(1,false);
                break;
            case R.id.rb_3:
                vp.setCurrentItem(2,false);
                break;
            case R.id.rb_4:
                vp.setCurrentItem(3,false);
                break;
            case R.id.rb_5:
                vp.setCurrentItem(4,false);
                break;
            case R.id.rb_6:
                vp.setCurrentItem(5,false);
                break;
            case R.id.rb_7:
                vp.setCurrentItem(6,false);
                break;
            case R.id.rb_8:
                vp.setCurrentItem(7,false);
                break;
        }
    }


    private ViewPager.OnPageChangeListener mOnPageChangeListener = new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int position) {
            switch (position) {
                case 0:
                    rb_1.setChecked(true);
                    break;
                case 1:
                    rb_2.setChecked(true);
                    break;
                case 2:
                    rb_3.setChecked(true);
                    break;
                case 3:
                    rb_4.setChecked(true);
                    break;
                case 4:
                    rb_5.setChecked(true);
                    break;
                case 5:
                    rb_6.setChecked(true);
                    break;
                case 6:
                    rb_7.setChecked(true);
                    break;
                case 7:
                    rb_8.setChecked(true);
                    break;
            }
        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    };

}
